﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using ProtoBuf.Message;

namespace UI
{
    public class UICopySmallBalanceExt : Battle.CopySmallBalance
    {
        public void Init(List<BaseResource> baseResources)
        {
            foreach (var obj in dropItems)
                Destroy(obj);
            dropItems.Clear();

            foreach (var info in baseResources)
            {
                var obj = GameObject.Instantiate(iconPrefab) as GameObject;
               
                obj.transform.SetParent(dropGrid.transform);
                obj.transform.localPosition = Vector3.zero;
                obj.transform.localScale = Vector3.one;
                obj.transform.localEulerAngles = Vector3.zero;
                obj.SetActive(true);

                obj.GetComponent<CommonIcon>().SetData(info.id, false, info.num);

                dropItems.Add(obj);
            }

            dropGrid.Reposition();
            scrollView.ResetPosition();
        }

        public TweenHeight height;
        public TweenAlpha alpha0,alpha1,alpha2,alpha3,alpha4;
        public GameObject btn;
        public override void PlayAni()
        {
            height.ResetToBeginning();
            alpha0.ResetToBeginning();
            alpha1.ResetToBeginning();
            alpha2.ResetToBeginning();
            alpha3.ResetToBeginning();
            alpha4.ResetToBeginning();

            height.PlayForward();
            alpha0.PlayForward();
            alpha1.PlayForward();
            alpha3.PlayForward();
            alpha2.PlayForward();
            alpha4.PlayForward();

            ManagerController.Instance.StartCoroutine(_ShowObj(0.35f));
        }

        IEnumerator _ShowObj(float delay)
        {
            btn.SetActive(false);
            yield return new WaitForSeconds(delay);
            btn.SetActive(true);
        }
    }
}